<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateMiniUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('mini_users', function (Blueprint $table) {
            $table->id();
            $table->string('openid')->unique()->comment('微信openid');
            $table->string('union_id')->nullable()->comment('微信unionid');
            $table->string('session_key')->nullable()->comment('微信会话密钥');
            $table->string('nickname')->nullable()->comment('昵称');
            $table->string('avatar')->nullable()->comment('头像');
            $table->string('phone')->nullable()->comment('手机号');
            $table->string('real_name')->nullable()->comment('真实姓名');
            $table->string('id_card')->nullable()->comment('身份证号');
            $table->integer('id_type')->default(1)->comment('证件类型 1:居民身份证 2:港澳台通行证 3:护照');
            $table->tinyInteger('status')->default(1)->comment('状态 0:禁用 1:启用');
            $table->timestamp('last_login_at')->nullable()->comment('最后登录时间');
            $table->timestamps();
            
            $table->index(['openid', 'status']);
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('mini_users');
    }
}
